home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Apple Developer Connection Student Program
/
ADC Tools Sampler CD Disk 3 1999.iso
/
Cool Demos, SDKs, & Tools
/
Demos⁄Tools⁄Offers
/
Eiffel for CW beta 3
/
EiffelS2
/
LIBRARY
/
MOTEL
/
Graphics.c
< prev
next >
Wrap
Text File
|
1999-05-09
|
15KB
|
707 lines
/*------------------------------------------------------------------*/
/* Eiffel/S II MacOS Runtime */
/*------------------------------------------------------------------*/
/* Author : Ian Joyner */
/* Release : 1.0 */
/* Date : Dec. 1997 */
/* Copyright : Ian Joyner */
/*------------------------------------------------------------------*/
/********************************************************************/
/* */
/* QUICKDRAW */
/* */
/********************************************************************/
#include <Quickdraw.h>
#include <Sound.h>
#include <Eiffel2.h>
POINTER platform_QD_GetPort ()
{
GrafPtr p;
GetPort (&p);
return (POINTER)p;
}
void platform_QD_SetPort (POINTER p)
{
SetPort ((GrafPtr)p);
}
POINTER platform_QD_white ()
{
return (POINTER)&qd.white;
}
POINTER platform_QD_black ()
{
return (POINTER)&qd.black;
}
POINTER platform_QD_gray ()
{
return (POINTER)&qd.gray;
}
POINTER platform_QD_light_gray ()
{
return (POINTER)&qd.ltGray;
}
POINTER platform_QD_dark_gray ()
{
return (POINTER)&qd.dkGray;
}
POINTER platform_QD_arrow ()
{
return (POINTER)&qd.arrow;
}
POINTER platform_QD_screen_bits ()
{
return (POINTER)&qd.screenBits;
}
INTEGER platform_QD_random_seed ()
{
return qd.randSeed;
}
void platform_QD_set_random_seed (INTEGER start)
{
qd.randSeed = start;
}
INTEGER platform_QD_screen_left ()
{
return qd.screenBits.bounds.left;
}
INTEGER platform_QD_screen_top ()
{
return qd.screenBits.bounds.top;
}
INTEGER platform_QD_screen_right ()
{
return qd.screenBits.bounds.right;
}
INTEGER platform_QD_screen_bottom ()
{
return qd.screenBits.bounds.bottom;
}
void platform_QD_move_to (INTEGER h, INTEGER v)
{
MoveTo (h, v);
}
void platform_QD_move (INTEGER dh, INTEGER dv)
{
Move (dh, dv);
}
void platform_QD_line_to (INTEGER h, INTEGER v)
{
LineTo (h, v);
}
void platform_QD_line (INTEGER dh, INTEGER dv)
{
Line (dh, dv);
}
void platform_QD_color_bit (INTEGER which_bit)
{
ColorBit (which_bit);
}
INTEGER platform_desktop_rectangle_left ()
{
return (*GetGrayRgn ())->rgnBBox.left;
}
INTEGER platform_desktop_rectangle_top ()
{
return (*GetGrayRgn ())->rgnBBox.top;
}
INTEGER platform_desktop_rectangle_right ()
{
return (*GetGrayRgn ())->rgnBBox.right;
}
INTEGER platform_desktop_rectangle_bottom ()
{
return (*GetGrayRgn ())->rgnBBox.bottom;
}
void platform_point_global_to_local (INTEGER *x, INTEGER *y)
{
Point p;
SetPt (&p, *x, *y);
GlobalToLocal (&p);
*x = p.h;
*y = p.v;
}
void platform_point_local_to_global (INTEGER *x, INTEGER *y)
{
Point p;
SetPt (&p, *x, *y);
LocalToGlobal (&p);
*x = p.h;
*y = p.v;
}
BOOLEAN platform_QD_done ()
{
return QDDone (NULL);
}
/********************************************************************/
/* */
/* QUICKDRAW text */
/* */
/********************************************************************/
/*void platform_QD_text_font (INTEGER the_font)
{
TextFont (the_font);
}
void platform_QD_text_face (INTEGER the_face)
{
TextFace (the_face);
}
void platform_QD_text_mode (INTEGER the_mode)
{
TextMode (the_mode);
}
void platform_QD_text_size (INTEGER new_size)
{
TextSize (new_size);
}*/
/********************************************************************/
/* */
/* PEN */
/* */
/********************************************************************/
void platform_get_pen (INTEGER *x, INTEGER *y)
{
Point p;
GetPen (&p);
*x = p.h;
*y = p.v;
}
void platform_set_pen_size (INTEGER width, INTEGER height)
{
PenSize (width, height);
}
void platform_set_pen_mode (INTEGER mode)
{
PenMode (mode);
}
/********************************************************************/
/* */
/* PORTs */
/* */
/********************************************************************/
INTEGER platform_graf_port_size ()
{
CGrafPort p;
return (sizeof (p));
}
void platform_SetPort (GrafPtr port)
{
SetPort (port);
}
INTEGER platform_port_left (GrafPtr gp)
{
return gp->portRect.left;
}
INTEGER platform_port_top (GrafPtr gp)
{
return gp->portRect.top;
}
INTEGER platform_port_right (GrafPtr gp)
{
return gp->portRect.right;
}
INTEGER platform_port_bottom (GrafPtr gp)
{
return gp->portRect.bottom;
}
void platform_port_invalidate (INTEGER l, INTEGER t, INTEGER r, INTEGER b)
{
Point lt, rb;
Rect rc;
SetRect (&rc, l, t, r, b);
InvalRect (&rc);
}
void platform_port_set_origin (INTEGER h, INTEGER v)
{
SetOrigin (h, v);
}
void platform_port_scroll (INTEGER l, INTEGER t, INTEGER r, INTEGER b, INTEGER dh, INTEGER dv, RgnHandle update_region)
{
Rect rc;
SetRect (&rc, l, t, r, b);
ScrollRect (&rc, dh, dv, update_region);
}
void platform_port_set_size (INTEGER width, INTEGER height)
{
PortSize (width, height);
}
void platform_port_move_to (INTEGER l, INTEGER t)
{
MovePortTo (l, t);
}
BOOLEAN platform_port_pixel (INTEGER h, INTEGER v)
{
return GetPixel (h, v);
}
/********************************************************************/
/* */
/* PATTERNs */
/* */
/********************************************************************/
INTEGER platform_pattern_size ()
{
Pattern p;
return (sizeof (p));
}
PatHandle platform_pattern_get (PatPtr p, INTEGER id)
{
PatHandle ph;
ph = GetPattern (id);
*p = **ph;
DisposeHandle ((Handle) ph);
}
PatHandle platform_pattern_get_from_list (PatPtr p, INTEGER list_id, INTEGER index)
{
GetIndPattern (p, list_id, index);
}
/********************************************************************/
/* */
/* BIT MAPs */
/* */
/********************************************************************/
INTEGER platform_bit_map_size ()
{
BitMap bm;
return (sizeof (bm));
}
void platform_bit_map_attach (BitMap *pbm, POINTER p_map)
{
pbm->baseAddr = p_map;
}
/********************************************************************/
/* */
/* SHAPESs */
/* */
/********************************************************************/
BOOLEAN shape_open;
BOOLEAN platform_no_shape_open ()
{
return (!shape_open);
}
#define QD_call(n, c)\
void n (INTEGER left, INTEGER top, INTEGER right, INTEGER bottom)\
{\
Rect r;\
\
SetRect (&r, left, top, right, bottom);\
c (&r);\
}
#define QD_call_fill(n, c)\
void n (INTEGER left, INTEGER top, INTEGER right, INTEGER bottom, const Pattern *p)\
{\
Rect r;\
\
SetRect (&r, left, top, right, bottom);\
c (&r, p);\
}
#define QD_callRRArc(n, c)\
void n (INTEGER left, INTEGER top, INTEGER right, INTEGER bottom,INTEGER w, INTEGER h)\
{\
Rect r;\
\
SetRect (&r, left, top, right, bottom);\
c (&r, w, h);\
}
#define QD_call_fillRRArc(n, c)\
void n (INTEGER left, INTEGER top, INTEGER right,INTEGER bottom, INTEGER w, INTEGER h, const Pattern *p)\
{\
Rect r;\
\
SetRect (&r, left, top, right, bottom);\
c (&r, w, h, p);\
}
#define QD_callT(n, c, t)\
void n (t rp)\
{\
c (rp);\
}
#define QD_call_fillT(n, c, t)\
void n (t rp, const Pattern *p)\
{\
c (rp, p);\
}
/********************************************************************/
/* */
/* LINEs */
/* */
/********************************************************************/
void platform_line_frame (INTEGER h1, INTEGER v1, INTEGER h2, INTEGER v2)
{
MoveTo (h1, v1);
LineTo (h2, v2);
}
/********************************************************************/
/* */
/* RECTANGLEs */
/* */
/********************************************************************/
QD_call (platform_rectangle_frame, FrameRect)
QD_call (platform_rectangle_paint, PaintRect)
QD_call_fill (platform_rectangle_fill, FillRect)
QD_call (platform_rectangle_erase, EraseRect)
QD_call (platform_rectangle_invert, InvertRect)
QD_call (platform_rectangle_invalidate, InvalRect)
QD_call (platform_rectangle_validate, ValidRect)
QD_call (platform_rectangle_set_clip, ClipRect)
void platform_rectangle_scroll (INTEGER left, INTEGER top, INTEGER right, INTEGER bottom, INTEGER dh, INTEGER dv, RgnHandle ur)
{
Rect r;
SetRect (&r, left, top, right, bottom);
ScrollRect (&r, dh, dv, ur);
}
/********************************************************************/
/* */
/* ELLIPSEs */
/* */
/********************************************************************/
QD_call (platform_ellipse_frame, FrameOval)
QD_call (platform_ellipse_paint, PaintOval)
QD_call_fill (platform_ellipse_fill, FillOval)
QD_call (platform_ellipse_erase, EraseOval)
QD_call (platform_ellipse_invert, InvertOval)
/********************************************************************/
/* */
/* ROUND RECTANGLEs */
/* */
/********************************************************************/
QD_callRRArc (platform_round_rectangle_frame, FrameRoundRect)
QD_callRRArc (platform_round_rectangle_paint, PaintRoundRect)
QD_call_fillRRArc (platform_round_rectangle_fill, FillRoundRect)
QD_callRRArc (platform_round_rectangle_erase, EraseRoundRect)
QD_callRRArc (platform_round_rectangle_invert, InvertRoundRect)
/********************************************************************/
/* */
/* ARCs */
/* */
/********************************************************************/
QD_callRRArc (platform_arc_frame, FrameArc)
QD_callRRArc (platform_arc_paint, PaintArc)
QD_call_fillRRArc (platform_arc_fill, FillArc)
QD_callRRArc (platform_arc_erase, EraseArc)
QD_callRRArc (platform_arc_invert, InvertArc)
/********************************************************************/
/* */
/* REGIONs */
/* */
/********************************************************************/
BOOLEAN region_is_open;
BOOLEAN platform_region_is_open ()
{
return (region_is_open);
}
int platform_region_size ()
{
Region r;
return (sizeof (r));
}
POINTER platform_region_new ()
{
return (POINTER) NewRgn ();
}
POINTER platform_region_open ()
{
OpenRgn ();
shape_open = true;
region_is_open = true;
return (POINTER) NewRgn ();
}
void platform_region_copy (RgnHandle src, RgnHandle dst)
{
CopyRgn (src, dst);
}
/* These aren't needed... no 32 to 16 bit conversions...
QD_callT (platform_region_frame, FrameRgn, RgnHandle)
QD_callT (platform_region_paint, PaintRgn, RgnHandle)
QD_call_fillT (platform_region_fill, FillRgn, RgnHandle)
QD_callT (platform_region_erase, EraseRgn, RgnHandle)
QD_callT (platform_region_invert, InvertRgn, RgnHandle)
QD_callT (platform_region_invalidate, InvalRgn, RgnHandle)
QD_callT (platform_region_validate, ValidRgn, RgnHandle) */
void platform_region_offset (RgnHandle r, INTEGER dh, INTEGER dv)
{
OffsetRgn (r, dh, dv);
}
void platform_region_close (RgnHandle r)
{
shape_open = false;
region_is_open = false;
CloseRgn (r);
}
/********************************************************************/
/* */
/* POLYGONs */
/* */
/********************************************************************/
POINTER platform_polygon_open ()
{
shape_open = true;
return ((POINTER) OpenPoly ());
}
/* These aren't needed... no 32 to 16 bit conversions...
QD_callT (platform_frame_polygon, FramePolygon, PolyHandle)
QD_callT (platform_paint_polygon, PaintPolygon, PolyHandle)
QD_call_fillT (platform_fill_polygon, FillPolygon, PolyHandle)
QD_callT (platform_erase_polygon, ErasePolygon, PolyHandle)
QD_callT (platform_invert_polygon, InvertPolygon, PolyHandle) */
void platform_polygon_offset (PolyHandle p, INTEGER dh, INTEGER dv)
{
OffsetPoly (p, dh, dv);
}
void platform_polygon_close (POINTER p) /* parameter ignored */
{
shape_open = false;
ClosePoly ();
}
/********************************************************************/
/* */
/* PICTUREs */
/* */
/********************************************************************/
PicHandle platform_picture_open (INTEGER left, INTEGER top, INTEGER right, INTEGER bottom, REAL h_res, REAL v_res)
{
OpenCPicParams pp;
SetRect (&pp.srcRect, left, top, right, bottom);
pp.hRes = h_res;
pp.vRes = v_res;
pp.version = -2;
pp.reserved1 = 0;
pp.reserved2 = 0;
shape_open = true;
return OpenCPicture (&pp);
}
PicHandle platform_picture_get (INTEGER id)
{
return GetPicture (id);
}
void platform_picture_comment (INTEGER kind, INTEGER sz, Handle d)
{
PicComment (kind, sz, d);
}
void platform_picture_draw (PicHandle p, INTEGER left, INTEGER top, INTEGER right, INTEGER bottom)
{
Rect bounds_rect;
SetRect (&bounds_rect, left, top, right, bottom);
DrawPicture (p, &bounds_rect);
}
void platform_picture_close (POINTER p) /* parameter ignored */
{
shape_open = false;
ClosePicture ();
}
/********************************************************************/
/* */
/* COLORs */
/* */
/********************************************************************/
void platform_invert_color (INTEGER *rp, INTEGER *gp, INTEGER *bp)
{
RGBColor c;
c.red = *rp;
c.green = *gp;
c.blue = *bp;
InvertColor (&c);
*rp = c.red;
*gp = c.green;
*bp = c.blue;
}
void platform_set_fore_color (INTEGER r, INTEGER g, INTEGER b)
{
RGBColor c;
c.red = r;
c.green = g;
c.blue = b;
RGBForeColor (&c);
}
void platform_set_back_color (INTEGER r, INTEGER g, INTEGER b)
{
RGBColor c;
c.red = r;
c.green = g;
c.blue = b;
RGBBackColor (&c);
}
void platform_get_fore_color (INTEGER *rp, INTEGER *gp, INTEGER *bp)
{
RGBColor c;
GetForeColor (&c);
*rp = c.red;
*gp = c.green;
*bp = c.blue;
}
void platform_get_back_color (INTEGER *rp, INTEGER *gp, INTEGER *bp)
{
RGBColor c;
GetBackColor (&c);
*rp = c.red;
*gp = c.green;
*bp = c.blue;
}
/********************************************************************/
/* */
/* STRINGs */
/* */
/********************************************************************/
void platform_draw_string (POINTER str)
{
Str255 scratch;
strcpy (scratch, str);
c2pstr ((char *)scratch); /* This might not be right if string is loaded from a resource */
DrawString (scratch);
}
INTEGER platform_string_width (POINTER str)
{
Str255 scratch;
strcpy (scratch, str);
c2pstr ((char *)scratch); /* This might not be right if string is loaded from a resource */
return (StringWidth (scratch));
}